@()(implicit session: Session)
@account.main("账号管理") {


    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li>
                <b style="font-size: 20px;">账号</b>
            </li>
            <li style="margin-left: 2em;">
                <a href="routes.AccountController.accountBefore()" ><i class="fa fa-cloud-upload"></i>
                    新增账号</a>
            </li>

            <li style="margin-left: 2em;">
                <a href="routes.AccountController.manageBefore()"><i class="fa fa-sliders"></i>
                    账号管理</a>
            </li>
        </ul>
    </div>

    <div class="row-fluid">

        <div class="row">

            <div class="col-md-12 col-sm-12">
                <div class="portlet blue-soft box">

                    <div class="portlet-title">
                        <div class="caption">
                            账号管理
                        </div>
                    </div>

                    <div class="portlet-body">


                        <div id="toolbar"></div>

                        <table class="table table-bordered table-hover " id="table" data-pagination="true" data-search="true"
                        data-toolbar="#toolbar" data-page-list="[10, 25, 50, 100, all]" data-search-align="left" data-multiple-search="true">
                        </table>


                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>


            $(function () {


                $("#table").bootstrapTable({
                    columns: [ {
                        field: "operation",
                        title: "操作",
                        formatter: function (value, row, index) {
                            var de = "<button class='delete' onclick='resetPassword(this)' value=\"" + row.name + "\" id='" + row.id + "' title='重置密码'><i class='fa fa-refresh'></i></button>" +
                                    "<button class='delete' onclick='openDelete(this)' value=\"" + row.name + "\" id='" + row.id + "' title='删除'><i class='fa fa-trash'></i></button>";
                            return de;
                        }
                    },
                        {
                            field: "id",
                            title: "ID"
                        }, {
                            field: "account",
                            title: "账号"
                        }, {
                            field: "name",
                            title: "指导老师"
                        }, {
                            field: "nums",
                            title: "菌种数"
                        }
                    ]
                });


                loadData();

            });

            function loadData() {
                $.ajax({
                    url: "@routes.AccountController.getAllAcount()",
                    type: "post",
                    success: function (data) {
                        $("#table").bootstrapTable("load", data)
                    }
                });
            }

            function resetPassword(obj) {
                swal({
                    title: "\n",
                    text: "确认要重置用户 \"" + obj.value + "\" 的密码？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确认',
                    cancelButtonText: "取消",
                    closeOnConfirm: false
                }, function () {
                    $.ajax({
                        url: "/grem/account/resetPassword?id=" + obj.id,
                        type: "post",
                        success: function () {
                            swal("\n", "重置成功", "success");
                        }
                    })
                })
            }

            function openDelete(obj) {

                swal({
                            title: '删除?',
                            text: "确认删除用户 \"" + obj.value + "\" ?",
                            type: 'warning',
                            showCancelButton: true,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: '确认',
                            cancelButtonText: "取消",
                            closeOnConfirm: false
                        }, function () {
                            $.ajax({
                                url: "/grem/account/deleteAccount?id=" + obj.id,
                                type: "delete",
                                success: function (data) {
                                    if (data.valid == "false") {
                                        swal("错误", data.message, "error")
                                    } else {
                                        swal({
                                            type: "success",
                                            title: "\n",
                                            text: "删除成功！"
                                        }, function () {
                                            loadData();
                                        })
                                    }
                                }
                            })
                        }
                )
            }




    </script>


}